package com.ruoyi.ethnicity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ethnicity.domain.TbEthnicity;
import com.ruoyi.ethnicity.service.ITbEthnicityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 民族信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/ethnicity/ethnicity")
public class TbEthnicityController extends BaseController
{
    @Autowired
    private ITbEthnicityService tbEthnicityService;

    /**
     * 查询民族信息列表
     */
    @PreAuthorize("@ss.hasPermi('ethnicity:ethnicity:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEthnicity tbEthnicity)
    {
        startPage();
        List<TbEthnicity> list = tbEthnicityService.selectTbEthnicityList(tbEthnicity);
        return getDataTable(list);
    }

    /**
     * 导出民族信息列表
     */
    @PreAuthorize("@ss.hasPermi('ethnicity:ethnicity:export')")
    @Log(title = "民族信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEthnicity tbEthnicity)
    {
        List<TbEthnicity> list = tbEthnicityService.selectTbEthnicityList(tbEthnicity);
        ExcelUtil<TbEthnicity> util = new ExcelUtil<TbEthnicity>(TbEthnicity.class);
        util.exportExcel(response, list, "民族信息数据");
    }

    /**
     * 获取民族信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ethnicity:ethnicity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbEthnicityService.selectTbEthnicityById(id));
    }

    /**
     * 新增民族信息
     */
    @PreAuthorize("@ss.hasPermi('ethnicity:ethnicity:add')")
    @Log(title = "民族信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEthnicity tbEthnicity)
    {
        return toAjax(tbEthnicityService.insertTbEthnicity(tbEthnicity));
    }

    /**
     * 修改民族信息
     */
    @PreAuthorize("@ss.hasPermi('ethnicity:ethnicity:edit')")
    @Log(title = "民族信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEthnicity tbEthnicity)
    {
        return toAjax(tbEthnicityService.updateTbEthnicity(tbEthnicity));
    }

    /**
     * 删除民族信息
     */
    @PreAuthorize("@ss.hasPermi('ethnicity:ethnicity:remove')")
    @Log(title = "民族信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbEthnicityService.deleteTbEthnicityByIds(ids));
    }
}
